package xyz.xuminghai.javafx_learn.animation.transition;

import javafx.animation.RotateTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.SequentialTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * 2023/7/30 7:56 星期日<br/>
 * 此Transition按顺序播放Animations列表。
 * 如果未指定其node属性，则此Transition的子级将继承node 。
 *
 * @author xuMingHai
 */
public class SequentialTransitionApp extends Application {

    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }


    @Override
    public void init() {
        Rectangle rectangle = new Rectangle(100.0, 100.0);
        Stop[] stops = {new Stop(0.2, Color.DARKTURQUOISE), new Stop(0.5, Color.DARKORCHID),
                new Stop(1.0, Color.ANTIQUEWHITE)};
        rectangle.setFill(new LinearGradient(0.0, 0.0,
                50.0, 50.0,
                false, CycleMethod.NO_CYCLE,
                stops));

        RotateTransition rotateTransition = new RotateTransition(Duration.millis(3000.0));
        rotateTransition.setToAngle(270.0);

        ScaleTransition scaleTransition = new ScaleTransition(Duration.millis(2000.0));
        scaleTransition.setByX(1.0);
        scaleTransition.setByY(1.0);

        SequentialTransition sequentialTransition = new SequentialTransition(rectangle, rotateTransition,
                scaleTransition);
        sequentialTransition.play();

        root.setCenter(rectangle);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
